/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-16 16:01:17
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-16 16:36:46
 */

import 'package:flutter/material.dart';
import 'package:flutter_data_center/model/light/light_module.dart';
import 'package:flutter_svg/svg.dart';

import '../../../constants.dart';

class LightItem extends StatefulWidget {
  const LightItem({Key key, this.light}) : super(key: key);
  final LightModel light;

  @override
  _LightItemState createState() => _LightItemState();
}

class _LightItemState extends State<LightItem> {
  bool status = false;
  @override
  Widget build(BuildContext context) {
    // TODO 上线后放开
    // status = widget.light.status;
    Color color = status
        ? Theme.of(context).primaryColor
        : Theme.of(context).primaryColor.withOpacity(0.3);
    return Container(
      padding: EdgeInsets.symmetric(
        horizontal: 15,
        vertical: 10,
      ),
      decoration: BoxDecoration(
        color: Color(0xffF8FAFB),
        borderRadius: BorderRadius.circular(15),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.end,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Row(
            children: [
              Container(
                width: 45,
                height: 45,
                padding: EdgeInsets.all(5),
                decoration: BoxDecoration(
                  color: Colors.white,
                  shape: BoxShape.circle,
                ),
                child: SvgPicture.asset("assets/icon/icon_light.svg",
                    color: color),
              ),
              SizedBox(width: 5),
              Expanded(
                child: Text(
                  widget.light.name,
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                    fontSize: 16,
                  ),
                ),
              ),
            ],
          ),
          Switch(
            value: status,
            activeTrackColor: Theme.of(context).primaryColor,
            activeColor: Colors.white,
            inactiveTrackColor: Color(0xffEAEAEA),
            onChanged: (value) {
              setState(() {
                setState(() {
                  status = value;
                });
              });
            },
          ),
        ],
      ),
    );
  }
}
